// Project: Salient
// http://salient.codeplex.com
// 
// Copyright 2010, Sky Sanders <sky at skysanders.net>
// Dual licensed under the MIT or GPL Version 2 licenses.
// http://salient.codeplex.com/license
// 
// Date: April 25 2010 

#region

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Text;
using Salient.Data.Common;

#endregion

namespace Salient.Data.SqlClient
{

 
 



    /// <summary>
    /// TODO: convertToPersistSecurityInfo etc etc
    /// </summary>
    [DefaultProperty("DataSource")]
    //[TypeConverter(typeof (SqlConnectionStringBuilderConverter))]
    public class SqlConnectionStringBuilder : ConnectionStringParser
    {


        #region Constructors

        ///<summary>
        ///</summary>
        public SqlConnectionStringBuilder()
            : this(String.Empty)
        {

        }

        ///<summary>
        ///</summary>
        ///<param name="connectionString"></param>
        public SqlConnectionStringBuilder(string connectionString)
        {
            Synonyms = SynonymTemplate;
            ConnectionString = connectionString;
        }

        #endregion // Constructors

        ///<summary>
        ///</summary>
        [RefreshProperties(RefreshProperties.All)]
        [Category("Data")]
        [Description("The connection string used to connect to the Data Source.")]
        public string ConnectionString
        {
            get { return ToString(); }
            set
            {
                Init();
                Parse(value);

            }
        }

        #region Properties



        ///<summary>
        ///</summary>
        [DisplayName(KeyApplicationName)]
        [RefreshProperties(RefreshProperties.All)]
        public string ApplicationName
        {
            get { return this[KeyApplicationName]; }
            set { this[KeyApplicationName] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyAsynchronousProcessing)]
        [RefreshProperties(RefreshProperties.All)]
        public bool AsynchronousProcessing
        {
            get { return Convert.ToBoolean(this[KeyAsynchronousProcessing]); }
            set { this[KeyAsynchronousProcessing] = value.ToString(); }
        }

        //[Editor ("Microsoft.VSDesigner.Data.Design.DBParametersEditor, " + Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
        ///<summary>
        ///</summary>
        [Editor("System.Windows.Forms.Design.FileNameEditor, System.Design, Version=2.0.0.0",
            "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0")]
        [DisplayName(KeyAttachDbFilename)]
        [RefreshProperties(RefreshProperties.All)]
        public string AttachDBFilename
        {
            get { return this[KeyAttachDbFilename]; }
            set { this[KeyAttachDbFilename] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyConnectionReset)]
        [RefreshProperties(RefreshProperties.All)]
        public bool ConnectionReset
        {
            get { return Convert.ToBoolean(this[KeyConnectionReset]); }
            set { this[KeyConnectionReset] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyConnectTimeout)]
        [RefreshProperties(RefreshProperties.All)]
        public int ConnectTimeout
        {
            get { return Convert.ToInt32(this[KeyConnectTimeout]); }
            set { this[KeyConnectTimeout] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyCurrentLanguage)]
        [RefreshProperties(RefreshProperties.All)]
        public string CurrentLanguage
        {
            get { return this[KeyCurrentLanguage]; }
            set { this[KeyCurrentLanguage] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyDataSource)]
        [RefreshProperties(RefreshProperties.All)]
        [TypeConverter(
            "System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter, System.Data, Version=2.0.0.0")]
        public string DataSource
        {
            get { return this[KeyDataSource]; }
            set { this[KeyDataSource] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyEncrypt)]
        [RefreshProperties(RefreshProperties.All)]
        public bool Encrypt
        {
            get { return Convert.ToBoolean(this[KeyEncrypt]); }
            set { this[KeyEncrypt] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyEnlist)]
        [RefreshProperties(RefreshProperties.All)]
        public bool Enlist
        {
            get { return Convert.ToBoolean(this[KeyEnlist]); }
            set { this[KeyEnlist] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyFailoverPartner)]
        [RefreshProperties(RefreshProperties.All)]
        [TypeConverter(
            "System.Data.SqlClient.SqlConnectionStringBuilder+SqlDataSourceConverter, System.Data, Version=2.0.0.0")]
        public string FailoverPartner
        {
            get { return this[KeyFailoverPartner]; }
            set { this[KeyFailoverPartner] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyInitialCatalog)]
        [RefreshProperties(RefreshProperties.All)]
        [TypeConverter("System.Data.SqlClient.SqlConnectionStringBuilder+SqlInitialCatalogConverter, Version=2.0.0.0")]
        public string InitialCatalog
        {
            get { return this[KeyInitialCatalog]; }
            set { this[KeyInitialCatalog] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyIntegratedSecurity)]
        [RefreshProperties(RefreshProperties.All)]
        public bool IntegratedSecurity
        {
            get { return Convert.ToBoolean(this[KeyIntegratedSecurity]); }
            set { this[KeyIntegratedSecurity] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        public bool IsFixedSize
        {
            get { return true; }
        }

        /// <summary>
        /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the 
        /// <see cref="T:System.Collections.Generic.IDictionary`2"/>.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the object that implements 
        /// <see cref="T:System.Collections.Generic.IDictionary`2"/>.
        /// </returns>
        public override ICollection<string> Keys
        {
            get { return KeysEx; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyLoadBalanceTimeout)]
        [RefreshProperties(RefreshProperties.All)]
        public int LoadBalanceTimeout
        {
            get { return Convert.ToInt32(this[KeyLoadBalanceTimeout]); }
            set { this[KeyLoadBalanceTimeout] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyMaxPoolSize)]
        [RefreshProperties(RefreshProperties.All)]
        public int MaxPoolSize
        {
            get { return Convert.ToInt32(this[KeyMaxPoolSize]); }
            set { this[KeyMaxPoolSize] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyMinPoolSize)]
        [RefreshProperties(RefreshProperties.All)]
        public int MinPoolSize
        {
            get { return Convert.ToInt32(this[KeyMinPoolSize]); }
            set { this[KeyMinPoolSize] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyMultipleActiveResultSets)]
        [RefreshProperties(RefreshProperties.All)]
        public bool MultipleActiveResultSets
        {
            get { return Convert.ToBoolean(this[KeyMultipleActiveResultSets]); }
            set { this[KeyMultipleActiveResultSets] = value.ToString(); }
        }


        /// <summary>
        /// TODO: GetValue for networkLibrary
        /// </summary>
        [DisplayName(KeyNetworkLibrary)]
        [RefreshProperties(RefreshProperties.All)]
        [TypeConverter("System.Data.SqlClient.SqlConnectionStringBuilder+NetworkLibraryConverter, System.Data, Version=2.0.0.0")]
        //[TypeConverterAttribute(typeof(NetworkLibraryConverter))]
        public string NetworkLibrary
        {
            get { return this[KeyNetworkLibrary]; }
            set { this[KeyNetworkLibrary] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyPacketSize)]
        [RefreshProperties(RefreshProperties.All)]
        public int PacketSize
        {
            get { return Convert.ToInt32(this[KeyPacketSize]); }
            set { this[KeyPacketSize] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyPassword)]
        [PasswordPropertyText(true)]
        [RefreshProperties(RefreshProperties.All)]
        public string Password
        {
            get { return this[KeyPassword]; }
            set { this[KeyPassword] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyPersistSecurityInfo)]
        [RefreshProperties(RefreshProperties.All)]
        public bool PersistSecurityInfo
        {
            get { return Convert.ToBoolean(this[KeyPersistSecurityInfo]); }
            set { this[KeyPersistSecurityInfo] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyPooling)]
        [RefreshProperties(RefreshProperties.All)]
        public bool Pooling
        {
            get { return Convert.ToBoolean(this[KeyPooling]); }
            set { this[KeyPooling] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyReplication)]
        [RefreshProperties(RefreshProperties.All)]
        public bool Replication
        {
            get { return Convert.ToBoolean(this[KeyReplication]); }
            set { this[KeyReplication] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyUserID)]
        [RefreshProperties(RefreshProperties.All)]
        public string UserID
        {
            get { return this[KeyUserID]; }
            set { this[KeyUserID] = value; }
        }

        /// <summary>
        /// TODO: verify
        /// </summary>
        [DisplayName(KeyTransactionBinding)]
        [RefreshProperties(RefreshProperties.All)]
        public string TransactionBinding
        {
            get { return this[KeyTransactionBinding]; }
            set { this[KeyTransactionBinding] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyWorkstationID)]
        [RefreshProperties(RefreshProperties.All)]
        public string WorkstationID
        {
            get { return this[KeyWorkstationID]; }
            set { this[KeyWorkstationID] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyTrustServerCertificate)]
        [RefreshProperties(RefreshProperties.All)]
        public bool TrustServerCertificate
        {
            get { return Convert.ToBoolean(this[KeyTrustServerCertificate]); }
            set { this[KeyTrustServerCertificate] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyTypeSystemVersion)]
        [RefreshProperties(RefreshProperties.All)]
        public string TypeSystemVersion
        {
            get { return this[KeyTypeSystemVersion]; }
            set { this[KeyTypeSystemVersion] = value; }
        }

        ///<summary>
        ///</summary>
        [DisplayName(KeyUserInstance)]
        [RefreshProperties(RefreshProperties.All)]
        public bool UserInstance
        {
            get { return Convert.ToBoolean(this[KeyUserInstance]); }
            set { this[KeyUserInstance] = value.ToString(); }
        }

        ///<summary>
        ///</summary>
        [RefreshProperties(RefreshProperties.All)]
        [DisplayName(KeyContextConnection)]
        public bool ContextConnection
        {
            get { return Convert.ToBoolean(this[KeyContextConnection]); }
            set { this[KeyContextConnection] = value.ToString(); }
        }

        #endregion // Properties
        private static bool ConvertToIntegratedSecurity(IConvertible value)
        {
            string valueString = value as string;

            if (!string.IsNullOrEmpty(valueString))
            {
                valueString = valueString.Trim().ToUpperInvariant();
                const string strSspi = "SSPI";
                if (valueString == strSspi)
                {
                    return true;
                }

            }
            return ConvertToBool(value);
        }

        private static bool ConvertToBool(IConvertible value)
        {
            string valueString = value as string;

            if (valueString == null)
            {
                bool flag;
                try
                {
                    flag = value.ToBoolean(CultureInfo.InvariantCulture);
                }
                catch
                {
                    throw new ArgumentException(string.Format("Could not convert value '{0}' to Integrated Security token", value), KeyIntegratedSecurity);
                }
                return flag;
            }

            valueString = valueString.Trim().ToUpperInvariant();

            const string strTrue = "TRUE";
            const string strYes = "YES";
            const string strFalse = "FALSE";
            const string strNo = "NO";

            if (valueString == strTrue || valueString == strYes)
            {
                return true;
            }

            if (valueString == strFalse || valueString == strNo)
            {
                return false;
            }

            bool returnValue;
            bool.TryParse(valueString, out returnValue);

            return returnValue;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        protected override string GetValue(string key, string value)
        {

            //System.ArgumentException: Invalid 'Packet Size'.  The value must be an integer >= 512 and <= 32768.
            //System.ArgumentException: Invalid value for key 'Network Library'.

            // 
            switch (key)
            {
                case KeyNetworkLibrary:
                    value = value.ToUpperInvariant().Trim();
                    if (!string.IsNullOrEmpty(value) && value != "DBNMPNTW" && value != "DBMSSOCN" && value != "DBMSSPXN" && value != "DBMSVINN" && value != "DBMSRPCN")
                    {
                        throw new ArgumentException(string.Format("Invalid Network Library value '{0}'. Valid are dbnmpntw, dbmssocn, dbmsspxn, dbmsvinn, dbmsrpcn or ''", value), KeyNetworkLibrary);
                    }
                    return value;

                case KeyPacketSize:
                    int packetSize;
                    if (!int.TryParse(value, out packetSize))
                    {
                        throw new ArgumentException(string.Format("Invalid Packet Size value {0}", value), KeyPacketSize);
                    }
                    if (packetSize < 512 || packetSize > 32768)
                        throw new ArgumentException(string.Format("Invalid Packet Size value {0}. The value must be an integer >= 512 and <= 32768.", value), KeyPacketSize);
                    return value;
                case KeyIntegratedSecurity:
                    return ConvertToIntegratedSecurity(value).ToString();

                default:
                    if (typeof(bool) == Defaults[GetKey(key)].GetType())
                    {
                        return ConvertToBool(value).ToString();
                    }
                    return value;
            }
        }

        /// <summary>
        /// Gets or sets the element with the specified key.
        /// </summary>
        /// <returns>
        /// The element with the specified key.
        /// </returns>
        /// <param name="keyword">The key of the element to get or set.</param>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.</exception>
        /// <exception cref="T:System.Collections.Generic.KeyNotFoundException">The property is retrieved and <paramref name="key"/>
        /// is not found.</exception>
        /// <exception cref="T:System.NotSupportedException">The property is set and the <see cref="T:System.Collections.Generic.IDictionary`2"/> 
        /// is read-only.</exception>
        public override string this[string keyword]
        {
            get
            {

                return ContainsKey(keyword) ? base[keyword] : Defaults[GetKey(keyword)].ToString();
            }
            set
            {
                base[keyword] = value;
            }
        }

        private void Init()
        {
            Clear();

            foreach (string key in Keys)
            {
                this[key] = Defaults[key].ToString();
            }
        }

        private bool ShouldSerialize(string keyword)
        {

            if (keyword == KeyPassword && !PersistSecurityInfo)
            {
                return false;
            }

            return !Defaults[GetKey(keyword)].ToString().Equals(this[keyword]);
        }

        /// <summary>
        /// Returns a copy of ConnectionString with supplied Password regardless of PersistSecurityInfo
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public string WithPassword(string password)
        {

            string pwd = Password;
            Password = password;
            string cstring = ConnectionString;
            if (!PersistSecurityInfo)
            {
                cstring = string.Format("{0}Password=\"{1}\";", cstring, password.Replace("\"", "\\\""));
            }
            Password = pwd;
            return cstring;

        }

        /// <summary>
        /// Returns a copy of ConnectionString with <paramref name="replacement"/>.
        /// To remove a value, simply supply the default.
        /// </summary>
        /// <param name="replacement"></param>
        /// <returns></returns>
        public string Replace(string replacement)
        {
            var original = ConnectionString;
            Parse(replacement);
            var returnValue = ConnectionString;
            ConnectionString = original;
            return returnValue;
        }

        /// <summary>
        /// Returns ConnectionString
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder cstring = new StringBuilder();

            foreach (string key in Keys)
            {
                if (ShouldSerialize(key))
                {
                    string value = Defaults[key].GetType() == typeof(string) ?
                        string.Format("\"{0}\"", this[key].Replace("\"", "\"\"")) :
                        this[key];

                    string entry = String.Format("{0}={1};", key, value);

                    cstring.Append(entry);
                }

            }
            return cstring.ToString();
        }


        #region Keys

        private const string KeyApplicationName = "Application Name";
        private const string KeyAsynchronousProcessing = "Asynchronous Processing";
        private const string KeyAttachDbFilename = "AttachDbFilename";
        private const string KeyConnectionReset = "Connection Reset";
        private const string KeyConnectTimeout = "Connect Timeout";
        private const string KeyContextConnection = "Context Connection";
        private const string KeyCurrentLanguage = "Current Language";
        private const string KeyDataSource = "Data Source";
        private const string KeyEncrypt = "Encrypt";
        private const string KeyEnlist = "Enlist";
        private const string KeyFailoverPartner = "Failover Partner";
        private const string KeyInitialCatalog = "Initial Catalog";
        private const string KeyIntegratedSecurity = "Integrated Security";
        private const string KeyLoadBalanceTimeout = "Load Balance Timeout";
        private const string KeyMaxPoolSize = "Max Pool Size";
        private const string KeyMinPoolSize = "Min Pool Size";
        private const string KeyMultipleActiveResultSets = "MultipleActiveResultSets";
        private const string KeyNetworkLibrary = "Network Library";
        private const string KeyPacketSize = "Packet Size";
        private const string KeyPassword = "Password";
        private const string KeyPersistSecurityInfo = "Persist Security Info";
        private const string KeyPooling = "Pooling";
        private const string KeyReplication = "Replication";
        private const string KeyTransactionBinding = "Transaction Binding";
        private const string KeyTrustServerCertificate = "TrustServerCertificate";
        private const string KeyTypeSystemVersion = "Type System Version";
        private const string KeyUserID = "User ID";
        private const string KeyUserInstance = "User Instance";
        private const string KeyWorkstationID = "Workstation ID";

        private static readonly ICollection<string> KeysEx = new ReadOnlyCollection<string>(new List<string>
            {
                KeyDataSource,
                KeyFailoverPartner,
                KeyAttachDbFilename,
                KeyInitialCatalog,
                KeyIntegratedSecurity,
                KeyPersistSecurityInfo,
                KeyUserID,
                KeyPassword,
                KeyEnlist,
                KeyPooling,
                KeyMinPoolSize,
                KeyMaxPoolSize,
                KeyAsynchronousProcessing,
                KeyConnectionReset,
                KeyMultipleActiveResultSets,
                KeyReplication,
                KeyConnectTimeout,
                KeyEncrypt,
                KeyTrustServerCertificate,
                KeyLoadBalanceTimeout,
                KeyNetworkLibrary,
                KeyPacketSize,
                KeyTypeSystemVersion,
                KeyApplicationName,
                KeyCurrentLanguage,
                KeyWorkstationID,
                KeyUserInstance,
                KeyContextConnection,
                KeyTransactionBinding
            });

        #endregion

        #region Defaults
        private static readonly Dictionary<string, object> Defaults = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
                        {
                            {KeyDataSource, ""},
                            {KeyFailoverPartner, ""},
                            {KeyAttachDbFilename, ""},
                            {KeyInitialCatalog, ""},
                            {KeyIntegratedSecurity, false},
                            {KeyPersistSecurityInfo, false},
                            {KeyUserID, ""},
                            {KeyPassword, ""},
                            {KeyEnlist, false},
                            {KeyPooling, true},
                            {KeyMinPoolSize, 0},
                            {KeyMaxPoolSize, 100},
                            {KeyAsynchronousProcessing, false},
                            {KeyConnectionReset, true},
                            {KeyMultipleActiveResultSets, false},
                            {KeyReplication, false},
                            {KeyConnectTimeout, 15},
                            {KeyEncrypt, false},
                            {KeyTrustServerCertificate, false},
                            {KeyLoadBalanceTimeout, 0},
                            {KeyNetworkLibrary, ""},
                            {KeyPacketSize, 8000},
                            {KeyTypeSystemVersion, "Latest"},
                            {KeyApplicationName, ".NET SqlClient Data Provider"},
                            {KeyCurrentLanguage, ""},
                            {KeyWorkstationID, ""},
                            {KeyUserInstance, false},
                            {KeyContextConnection, false},
                            {KeyTransactionBinding, "Implicit Unbind"}
                        };
        #endregion

        #region Synonymns
        private const string SynAddr = "ADDR";
        private const string SynAddress = "ADDRESS";
        private const string SynApp = "APP";
        private const string SynApplicationname = "APPLICATION NAME";
        private const string SynAsynchronousprocessing = "ASYNCHRONOUS PROCESSING";
        private const string SynAttachdbfilename = "ATTACHDBFILENAME";
        private const string SynConnectionreset = "CONNECTION RESET";
        private const string SynConnectiontimeout = "CONNECTION TIMEOUT";
        private const string SynConnecttimeout = "CONNECT TIMEOUT";
        private const string SynContextconnection = "CONTEXT CONNECTION";
        private const string SynCurrentlanguage = "CURRENT LANGUAGE";
        private const string SynDatabase = "DATABASE";
        private const string SynDatasource = "DATA SOURCE";
        private const string SynEncrypt = "ENCRYPT";
        private const string SynEnlist = "ENLIST";
        private const string SynFailoverpartner = "FAILOVER PARTNER";
        private const string SynInitialcatalog = "INITIAL CATALOG";
        private const string SynIntegratedsecurity = "INTEGRATED SECURITY";
        private const string SynLanguage = "LANGUAGE";
        private const string SynLoadbalancetimeout = "LOAD BALANCE TIMEOUT";
        private const string SynMaxpoolsize = "MAX POOL SIZE";
        private const string SynMinpoolsize = "MIN POOL SIZE";
        private const string SynMultipleactiveresultsets = "MULTIPLEACTIVERESULTSETS";
        private const string SynNet = "NET";
        private const string SynNetwork = "NETWORK";
        private const string SynNetworkaddress = "NETWORK ADDRESS";
        private const string SynNetworklibrary = "NETWORK LIBRARY";
        private const string SynPacketsize = "PACKET SIZE";
        private const string SynPassword = "PASSWORD";
        private const string SynPersistsecurityinfo = "PERSISTSECURITYINFO";
        private const string SynPersistsecurityinfo1 = "PERSIST SECURITY INFO";
        private const string SynPooling = "POOLING";
        private const string SynPwd = "PWD";
        private const string SynReplication = "REPLICATION";
        private const string SynServer = "SERVER";
        private const string SynTimeout = "TIMEOUT";
        private const string SynTransactionbinding = "TRANSACTION BINDING";
        private const string SynTrustedConnection = "TRUSTED_CONNECTION";
        private const string SynTrustservercertificate = "TRUSTSERVERCERTIFICATE";
        private const string SynTYPESYSTEMVERSION = "TYPE SYSTEM VERSION";
        private const string SynUid = "UID";
        private const string SynUser = "USER";
        private const string SynUserid = "USER ID";
        private const string SynUserinstance = "USER INSTANCE";
        private const string SynWorkstationid = "WORKSTATION ID";
        private const string SynWsid = "WSID";

        private static readonly IDictionary<string, string> SynonymTemplate = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    {SynApp, KeyApplicationName},
                    {SynApplicationname, KeyApplicationName},

                    {SynAttachdbfilename, KeyAttachDbFilename},


                    {SynTimeout, KeyConnectTimeout},
                    {SynConnecttimeout, KeyConnectTimeout},
                    {SynConnectiontimeout, KeyConnectTimeout},

                    {SynConnectionreset, KeyConnectionReset},

                    {SynLanguage, KeyCurrentLanguage},
                    {SynCurrentlanguage, KeyCurrentLanguage},

                    {SynDatasource, KeyDataSource},
                    {SynServer, KeyDataSource},
                    {SynAddress, KeyDataSource},
                    {SynAddr, KeyDataSource},
                    {SynNetworkaddress, KeyDataSource},

                    {SynEncrypt, KeyEncrypt},

                    {SynEnlist, KeyEnlist},

                    {SynInitialcatalog, KeyInitialCatalog},
                    {SynDatabase, KeyInitialCatalog},

                    {SynIntegratedsecurity, KeyIntegratedSecurity},
                    {SynTrustedConnection, KeyIntegratedSecurity},

                    {SynMaxpoolsize, KeyMaxPoolSize},

                    {SynMinpoolsize, KeyMinPoolSize},

                    {SynMultipleactiveresultsets, KeyMultipleActiveResultSets},

                    {SynAsynchronousprocessing, KeyAsynchronousProcessing},


                    {SynNet, KeyNetworkLibrary},
                    {SynNetwork, KeyNetworkLibrary},
                    {SynNetworklibrary, KeyNetworkLibrary},

                    {SynPacketsize, KeyPacketSize},

                    {SynPassword, KeyPassword},
                    {SynPwd, KeyPassword},

                    {SynPersistsecurityinfo, KeyPersistSecurityInfo},
                    {SynPersistsecurityinfo1, KeyPersistSecurityInfo},

                    {SynPooling, KeyPooling},

                    {SynUid, KeyUserID},
                    {SynUser, KeyUserID},
                    {SynUserid, KeyUserID},


                    {SynWsid, KeyWorkstationID},
                    {SynWorkstationid, KeyWorkstationID},

                    {SynUserinstance, KeyUserInstance},

                    {SynContextconnection, KeyContextConnection},

                    {SynTransactionbinding, KeyTransactionBinding},

                    {SynFailoverpartner, KeyFailoverPartner},

                    {SynReplication, KeyReplication},

                    {SynTrustservercertificate, KeyTrustServerCertificate},

                    {SynLoadbalancetimeout, KeyLoadBalanceTimeout},

                    {SynTYPESYSTEMVERSION, KeyTypeSystemVersion}

                };
        #endregion

        
        
    }
}
